package com.qch.service;

import com.qch.pojo.OrderDO;
import com.qch.registry.OrderRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @Author qch
 * @Date 2021/5/21
 */
@Service
public class OrderServiceImpl implements OrderService{
    @Autowired
    private OrderRegistry orderRegistry;

    public OrderDO queryByOrderId(String orderId) {

        OrderDO orderDO=new OrderDO();
        orderDO.setOrderId(orderId);
        Example<OrderDO> example=Example.of(orderDO);
        Optional<OrderDO> one = orderRegistry.findOne(example);
        OrderDO result = one.get();
        return result;
    }
    public void insert(OrderDO orderDO) {
        orderRegistry.save(orderDO);
    }

    @Override
    public void update(OrderDO orderDO) {
        orderRegistry.save(orderDO);
    }

    public List<OrderDO> queryAll(String createBy) {

        OrderDO orderDO=new OrderDO();
        orderDO.setCreateBy(createBy);
        orderDO.setStatus("超时已取消");
        Example<OrderDO> example=Example.of(orderDO);
        List<OrderDO> all = orderRegistry.findAll(example);
        return all;
    }
}
